<html>
<head><meta charset="utf-8"><title>Question about MIR locals assumption · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html">Question about MIR locals assumption</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216719192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Question%20about%20MIR%20locals%20assumption/near/216719192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html#216719192">(Nov 14 2020 at 09:48)</a>:</h4>
<p>Given a function that have 2 parameters, 3 constants, and 4 compiler-generated temporaries. Can I assume that the index of all of those locals are unique, and in the range 0 to 8? ie, can I create a <code>Vec</code> with (2 + 3 + 4) 8 booleans, and use the index of each locals to index that <code>Vec</code>?</p>



<a name="216719210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Question%20about%20MIR%20locals%20assumption/near/216719210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html#216719210">(Nov 14 2020 at 09:48)</a>:</h4>
<p>Or do I need to use a <code>HashMap</code>?</p>



<a name="216719312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Question%20about%20MIR%20locals%20assumption/near/216719312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html#216719312">(Nov 14 2020 at 09:50)</a>:</h4>
<p>I forgot the return value. So my <code>Vec</code> should have 9 elements. Same question. Can I use <code>locals.index() + 1</code>  to index the <code>Vec</code>?</p>



<a name="216722174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Question%20about%20MIR%20locals%20assumption/near/216722174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html#216722174">(Nov 14 2020 at 10:53)</a>:</h4>
<p>You can use <code>IndexVec</code>. This is what is used to store all locals in <code>mir::Body</code> too.</p>



<a name="216722226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Question%20about%20MIR%20locals%20assumption/near/216722226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html#216722226">(Nov 14 2020 at 10:54)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html#structfield.local_decls">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html#structfield.local_decls</a></p>



<a name="216722813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Question%20about%20MIR%20locals%20assumption/near/216722813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Question.20about.20MIR.20locals.20assumption.html#216722813">(Nov 14 2020 at 11:09)</a>:</h4>
<p>Effectively, this makes sense.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>